package com.menhai.personmanagement.controller;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.menhai.personmanagement.entity.*;
import com.menhai.personmanagement.entity.vo.FrontPageVo;

import org.apache.ibatis.annotations.Param;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.menhai.personmanagement.entity.co.MbReportCardCO;
import com.menhai.personmanagement.entity.vo.MbReportCardVo;
import com.menhai.personmanagement.services.FollowupRecordService;
import com.menhai.personmanagement.services.ICodelistService;
import com.menhai.personmanagement.services.IMbPopulationService;
import com.menhai.personmanagement.services.ReportCardService;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.StyleSet;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 报卡管理表 前端控制器
 * </p>
 *
 * @author shikun
 * @since 2021-11-25
 */

@Slf4j
@RestController
@RequestMapping("/reportCard")
public class ReportCardController {

     @Autowired
     private FollowupRecordService followupRecordService;
     @Autowired
     private ReportCardService reportCardService;
     @Autowired
     private IMbPopulationService iMbPopulationService;
     @Autowired
     private ICodelistService iCodelistService;


	/**
	 * @describe 患者列表
	 * @param mbReportCardCO
	 * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.menhai.personmanagement.entity.MbReportCard>
	 * @Date 2021/12/14 15:47
	 * @author shikun
	 */
	@RequestMapping("/selectByList")
	public IPage<MbReportCardVo> selectByList(MbReportCardCO mbReportCardCO){
		return reportCardService.selectByList(mbReportCardCO);
	}


	//页面初始化加载行政区划(省)
     @RequestMapping("/province")
     public Object selectPrivince(FollowupRecord followupRecord,String followupDateStr,String zzjxcsfCxsfrqStr){
		 //新增随访记录
		 return reportCardService.selectProvince();
     }
     
     //页面初始化卡片编号
     @RequestMapping("/initCardNo")
     public Object initCardNo(){
		 //新增随访记录
		 Map<String,Object> map = new HashMap<String,Object>();
		 map.put("bkbh", getStringDateRandom());
		 return map;
     }
     
     //加载行政区划(市)
     @RequestMapping("/city")
     public Object selectCity(HttpServletRequest request, HttpServletResponse response){
		 //新增随访记录
		 String cprovinceStr = request.getParameter("cprovinceStr");
		 String cprovince = request.getParameter("cprovince");
		 return reportCardService.selectCity(cprovinceStr+"%00", cprovince);
     }
     
    //加载行政区划(区)
     @RequestMapping("/county")
     public Object selectcounty(HttpServletRequest request, HttpServletResponse response){
		 //新增随访记录
		 String cprovinceStr = request.getParameter("cprovinceStr");
		 String cprovince = request.getParameter("cprovince");
		 return reportCardService.selectCity(cprovinceStr+"%", cprovince);
     }
     
     //加载行政区划(乡镇)
     @RequestMapping("/township")
     public Object selecttownship(HttpServletRequest request, HttpServletResponse response){
		 //新增随访记录
		 String cprovinceStr = request.getParameter("cprovinceStr");
		 String cprovince = request.getParameter("cprovince");
		 return reportCardService.selectCity(cprovinceStr+"%000", cprovince);
     }
     
     //加载医院-镇
     @RequestMapping("/zhen")
     public Object getZhenList(HttpServletRequest request, HttpServletResponse response){
		 String hosnum = request.getParameter("hosnum");
		 return reportCardService.getZhenList(hosnum);
     }
     
     //加载医院-村
     @RequestMapping("/cun")
     public Object getCunList(HttpServletRequest request, HttpServletResponse response){
		 String hosnum = request.getParameter("hosnum");
		 return reportCardService.getCunList(hosnum);
     }

     //新建慢病报卡
     @RequestMapping("/add")
     public Object addMbReportCard(MbReportCard mbReportCard) throws Exception{
		 Map<String, Object> map = null;
		 //新建时间
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 mbReportCard.setAddTime(sdf.format(new Date()));
		 mbReportCard.setIsDelete("1");
		 //新增慢病报卡
		 map = reportCardService.addMbReportCard(mbReportCard);
		 return map;
     }
     
     //查询人口姓名集合
     @RequestMapping("/selectNameList")
     public Object selectNameList(HttpServletRequest request, HttpServletResponse response){
		 String patientName = request.getParameter("patientName");
		 String hosnum = request.getParameter("hosnum");
		 String mblx = request.getParameter("mblx");
		 return iMbPopulationService.selectReportCardName(patientName,hosnum,mblx);
     }
     
     //查询人口姓名集合
     @RequestMapping("/getReportPatient")
     public Object getReportPatient(HttpServletRequest request, HttpServletResponse response){
		 String patientName = request.getParameter("patientName");
		 String hosnum = request.getParameter("hosnum");
		 String mblx = request.getParameter("mblx");
		 return reportCardService.getReportPatient(patientName,hosnum,mblx);
     }
     
     //查询人口姓名集合
     @RequestMapping("/selectPopulationInfo")
     public Object selectPopulationInfo(HttpServletRequest request, HttpServletResponse response){
		 String id = request.getParameter("patientId");
		 String mblx = request.getParameter("mblx");
		 return iMbPopulationService.selectReportCardById(id,mblx);
     }
     
     //根据条件查询
     @RequestMapping("/getListByCondition")
     public Object getListByCondition(HttpServletRequest request, HttpServletResponse response){
		 String patientName = request.getParameter("patientName");
		 String shstatus = request.getParameter("shstatus");
		 String sbstatus = request.getParameter("sbstatus");
		 String startDate = request.getParameter("startDate");
		 String endDate = request.getParameter("endDate");
		 return reportCardService.getListByCondition(patientName, shstatus, sbstatus, startDate, endDate);
     }
     
     @RequestMapping(value = "/getListByConditionByPage", method = RequestMethod.POST)
	 public Object getListByConditionByPage(HttpServletRequest request, HttpServletResponse response,MbReportCard mbreportCard) throws Exception {
		 String minAge=request.getParameter("minAge");
		 String maxAge=request.getParameter("maxAge");
		 String startDate=request.getParameter("startDate");
		 String endDate=request.getParameter("endDate");
		 List<String> hosnumarray = new ArrayList<>();
		 if(!StringUtils.isEmpty(request.getParameter("hosnumarray"))) {
			 hosnumarray = Arrays.stream(request.getParameter("hosnumarray").split(",")).collect(Collectors.toList());
		 }
		 String hosnumstr=request.getParameter("hosnumarray");
		 IPage<MbReportCard> list = reportCardService.getListByConditionByPage(mbreportCard,minAge,maxAge,startDate,endDate,hosnumarray,hosnumstr);
		 return list;
	 }

	/**
	 * 返回格式yyyyMMddHHmmss+4位随机数
	 * @return
	 */
	public static String getStringDateRandom() {
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		String dateString = formatter.format(currentTime);
		int random = (int)((Math.random()*9+1)*1000);
		String randomString = dateString+""+random;
		System.out.println(randomString);
		return randomString;
	}

	//新建删除慢病报卡
    @RequestMapping("/deleteByBkbh")
    public Object deleteByBkbh(HttpServletRequest request, HttpServletResponse response) throws Exception{
		Map<String, Object> map = null;
		String bkbh = request.getParameter("bkbh");
		//新增慢病报卡
		map = reportCardService.updateIsDelete(bkbh);
		return map;
    }
     
    
    //慢病报卡上报
    @RequestMapping("/updateSbstatus")
    public Object updateSbstatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		Map<String, Object> map = null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String bkbh = request.getParameter("bkbh");
		//慢病报卡上报
		map = reportCardService.updateSbstatus(formatter.format(new Date()), bkbh);
		return map;
    }
    
    
    //慢病报卡取消上报
    @RequestMapping("/deleteSbstatus")
    public Object deleteSbstatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		Map<String, Object> map = null;
		String bkbh = request.getParameter("bkbh");
		//慢病报卡取消上报
		map = reportCardService.deleteSbstatus(bkbh);
		return map;
    }
    
    //慢病报卡审核
    @RequestMapping("/updateShstatus")
    public Object updateShstatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		Map<String, Object> map = null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String bkbh = request.getParameter("bkbh");
		//慢病报卡审核
		map = reportCardService.updateShstatus(formatter.format(new Date()), bkbh);
		return map;
    }
    
    
    //慢病报卡取消审核
    @RequestMapping("/deleteShstatus")
    public Object deleteShstatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		Map<String, Object> map = null;
		String bkbh = request.getParameter("bkbh");
		//慢病报卡取消审核
		map = reportCardService.deleteShstatus(bkbh);
		return map;
    }

	/**
	 * @describe 每日慢病数
	 * @param superiorCode
	 * @Return java.util.List<com.menhai.personmanagement.entity.vo.MbReportCardVo>
	 * @Date 2022/1/24 9:56
	 * @author shikun
	 */
	@RequestMapping("/selectBysuperiorCodeAndGroup")
	public List<MbReportCardVo> selectBysuperiorCodeAndGroup(String superiorCode){
		List<MbReportCardVo> list = reportCardService.selectBysuperiorCodeAndGroup(superiorCode);
		return list;
	}

	/**
	 * @describe 慢病患者年龄统计
	 * @param superiorCode
	 * @Return java.util.List<com.menhai.personmanagement.entity.vo.MbReportCardVo>
	 * @Date 2022/1/24 10:35
	 * @author shikun
	 */
	@RequestMapping("/selectPatientAgeCombination")
	public List<MbReportCardVo> selectPatientAgeCombination(String superiorCode){
		List<MbReportCardVo> list = reportCardService.selectPatientAgeCombination(superiorCode);
		return list;
	}

	/**
	 * @describe 慢病患者病症统计
	 * @param superiorCode
	 * @Return java.util.List<com.menhai.personmanagement.entity.vo.MbReportCardVo>
	 * @Date 2022/1/24 10:48
	 * @author shikun
	 */
	@RequestMapping("/selectByGroupMbType")
	public List<MbReportCardVo> selectByGroupMbType(String superiorCode){
		List<MbReportCardVo> list = reportCardService.selectByGroupMbType(superiorCode);
		return list;
	}

	@RequestMapping("/sicknumberstatistics")
	public MbReportCardVo sicknumberstatistics(String superiorCode){
		return reportCardService.sicknumberstatistics(superiorCode);
	}

	/**
	 * @describe 慢病患者病症统计 前五
	 * @param superiorCode
	 * @Return java.util.List<com.menhai.personmanagement.entity.vo.MbReportCardVo>
	 * @Date 2022/1/24 11:14
	 * @author shikun
	 */
	@RequestMapping("/selectByGroupMbTypeLimltOrder")
	public List<MbReportCardVo> selectByGroupMbTypeLimltOrder(String superiorCode){
		List<MbReportCardVo> list = reportCardService.selectByGroupMbTypeLimltOrder(superiorCode);
		return list;
	}

    //根据报卡编号查询数据
    @RequestMapping("/getOneById")
    public Object getOneById(HttpServletRequest request, HttpServletResponse response){
		//新增随访记录
		String bkbh = request.getParameter("bkbh");
		return reportCardService.getOneById(bkbh);
    }
    
    
    //慢病报卡审核
    @RequestMapping("/updateMbReportCard")
    public Object updateMbReportCard(MbReportCard mbReportCard) throws Exception{
		//慢病报卡审核
		return reportCardService.updateMbReportCard(mbReportCard);
    }

    //获取慢病信息列表
    @RequestMapping("/getChronicList")
    public Object getChronicList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		//慢病报卡审核
		return iCodelistService.getChronicList();
    }
    
    
    //根据当前系统时间，重新计算年龄
    @RequestMapping("/updateAge")
    public Object updateAge(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String bkbh = request.getParameter("bkbh");
		//更新年龄
		return reportCardService.updateAge(bkbh);
    }
    
    //规范人员管理统计表
    @RequestMapping("/chronicPatientGroupsStatistics") 
    public Object chronicPatientGroupsStatistics(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String hosnum = request.getParameter("hosnum");
		String year = request.getParameter("year");
		//更新年龄
		return reportCardService.chronicPatientGroupsStatistics(hosnum,year);
    }
    
    
    //导出规范人员管理统计表
    @RequestMapping("/exportChronicPatientGroupsStatistics")
    public void exportChronicPatientGroupsStatistics(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String hosnum = request.getParameter("hosnum");
		String year = request.getParameter("year");
		List<Map<String, Object>> chronicPatientGroupsStatistics = reportCardService.chronicPatientGroupsStatistics(hosnum,year);
		ExcelWriter writer = ExcelUtil.getWriter();

		List<String> header1 = new LinkedList<>();
		header1.add("村名称");
		header1.add("总人口");
		header1.add("确诊人数");
		header1.add("高血压");
		header1.add("");
		header1.add("糖尿病");
		header1.add("");
		header1.add("冠心病");
		header1.add("");
		header1.add("肿瘤");
		header1.add("");
		header1.add("精神病");
		header1.add("");
		header1.add("其他");
		header1.add("");
		LinkedList<Object> header2 = new LinkedList<>();
		header2.add("");
		header2.add("");
		header2.add("");
		header2.add("登记人数");
		header2.add("规范管理人数");
		header2.add("登记人数");
		header2.add("规范管理人数");
		header2.add("登记人数");
		header2.add("规范管理人数");
		header2.add("登记人数");
		header2.add("规范管理人数");
		header2.add("登记人数");
		header2.add("规范管理人数");
		header2.add("登记人数");
		header2.add("规范管理人数");
		writer.writeHeadRow(header1);
		writer.merge(0,0,3,4,null,false);
		writer.merge(0,0,5,6,null,false);
		writer.merge(0,0,7,8,null,false);
		writer.merge(0,0,9,10,null,false);
		writer.merge(0,0,11,12,null,false);
		writer.merge(0,0,13,14,null,false);
		writer.writeHeadRow(header2);
		writer.merge(0, 1, 0, 0, null, false);
		writer.merge(0, 1, 1, 1, null, false);
		writer.merge(0, 1, 2, 2, null, false);
		List<List<String>> rows = new LinkedList<>();
		for (Map<String, Object> map : chronicPatientGroupsStatistics) {
			LinkedList<String> row = CollUtil.newLinkedList(map.get("cunName").toString(),map.get("cunTotal").toString(),
					map.get("cunQZTotal").toString(),map.get("gxydjTotal").toString(),map.get("gxygfglTotal").toString(),
					map.get("tnbdjTotal").toString(),map.get("tnbgfglTotal").toString(),map.get("gxbdjTotal").toString(),
					map.get("gxbgfglTotal").toString(),map.get("zldjTotal").toString(),map.get("zlgfglTotal").toString(),
					map.get("jsbdjTotal").toString(),map.get("jsbgfglTotal").toString(),map.get("qtdjTotal").toString(),
					map.get("qtgfglTotal").toString());
			rows.add(row);
		}
		writer.write(rows,true);
		//调整列宽度
		writer.setColumnWidth(0, 20);
		writer.setColumnWidth(1, 10);
		writer.setColumnWidth(2, 10);
		writer.setColumnWidth(3, 10);
		writer.setColumnWidth(4, 15);
		writer.setColumnWidth(5, 10);
		writer.setColumnWidth(6,15);
		writer.setColumnWidth(7,10);
		writer.setColumnWidth(8,15);
		writer.setColumnWidth(9,10);
		writer.setColumnWidth(10,15);
		writer.setColumnWidth(11,10);
		writer.setColumnWidth(12,15);
		writer.setColumnWidth(13,10);
		writer.setColumnWidth(14,15);
         response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String((year+"年规范人员管理统计表").getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    //规范人员管理统计表
    @RequestMapping("/ywsyPatient") 
    public Object ywsyPatient(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String hosnum = request.getParameter("hosnum");
		String patientName = request.getParameter("patientName");
		String mbType = request.getParameter("mbType");
		//更新年龄
		return reportCardService.ywsyPatient(hosnum, patientName, mbType);
    }
    
    
    //慢病人员药品使用统计患者信息
    @RequestMapping("/mbryypsybPatientInfo") 
    public Object mbryypsybPatientInfo(HttpServletRequest request, HttpServletResponse response) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String bkbh = request.getParameter("bkbh");
		//病人信息
		map.put("patientInfo", reportCardService.mbryypsybPatientInfo(bkbh));
		//药品信息
		map.put("medInfo", reportCardService.mbryypsybPatientMedInfo(bkbh));
		//更新年龄
		return map;
    }
    
    
    //导出慢病人员药品使用统计表
    @RequestMapping("/exportMbryypsybStatistics")
    public void exportMbryypsybStatistics(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String bkbh = request.getParameter("bkbh");
		Map<String, Object> mbryypsybPatientInfo = reportCardService.mbryypsybPatientInfo(bkbh);
		List<Map<String, Object>> mbryypsybPatientMedInfo = reportCardService.mbryypsybPatientMedInfo(bkbh);
		ExcelWriter writer = ExcelUtil.getWriter();
		//去掉头部背景颜色
		StyleSet styleSet = writer.getStyleSet();
		styleSet.setBackgroundColor(IndexedColors.WHITE, true);
		List<String> header1 = new LinkedList<>();
		header1.add("姓名");
		header1.add(mbryypsybPatientInfo.get("patientName").toString());
		header1.add("性别");
		header1.add(mbryypsybPatientInfo.get("sex").toString());
		header1.add("出生年月");
		header1.add(mbryypsybPatientInfo.get("birthDay").toString());
		header1.add("联系电话");
		header1.add(mbryypsybPatientInfo.get("lxdh").toString());
		header1.add("慢性病种");
		header1.add(mbryypsybPatientInfo.get("mbType").toString());
		LinkedList<Object> header2 = new LinkedList<>();
		header2.add("家庭住址");
		header2.add(mbryypsybPatientInfo.get("newaddress").toString());
		header2.add("");
		header2.add("");
		header2.add("");
		header2.add("");
		header2.add("");
		header2.add("");
		header2.add("");
		header2.add("");
		writer.writeHeadRow(header1);
		writer.writeHeadRow(header2);
		writer.merge(1,1,1,9,null,false);
		List<String> header3 = new LinkedList<>();
		header3.add("慢性病用药");
		header3.add("");
		header3.add("");
		header3.add("");
		header3.add("");
		header3.add("");
		header3.add("");
		header3.add("");
		header3.add("");
		header3.add("");
		writer.writeHeadRow(header3);
		writer.merge(2,2,0,9,null,false);
		List<String> header4 = new LinkedList<>();
		header4.add("序号");
		header4.add("药物名称");
		header4.add("");
		header4.add("");
		header4.add("每日/次");
		header4.add("");
		header4.add("");
		header4.add("每日/mg");
		header4.add("");
		header4.add("");
		writer.writeHeadRow(header4);
		writer.merge(3,3,1,3,null,false);
		writer.merge(3,3,4,6,null,false);
		writer.merge(3,3,7,9,null,false);
		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<mbryypsybPatientMedInfo.size();i++){
			Map<String,Object> map=mbryypsybPatientMedInfo.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(""+(i+1),
					map.get("medName").toString(),"","",
					map.get("mrc").toString(),"","",
					map.get("mrmg").toString(),"","");
			rows.add(row);
		}
		writer.write(rows,true);
		for(int i=4;i<4+(mbryypsybPatientMedInfo.size());i++){
			writer.merge(i,i,1,3,null,false);
			writer.merge(i,i,4,6,null,false);
			writer.merge(i,i,7,9,null,false);
		}
		//调整列宽度
		writer.setColumnWidth(0, 10);
		writer.setColumnWidth(1, 8);
		writer.setColumnWidth(2, 8);
		writer.setColumnWidth(3,8);
		writer.setColumnWidth(4, 15);
		writer.setColumnWidth(5, 10);
		writer.setColumnWidth(6,10);
		writer.setColumnWidth(7,15);
		writer.setColumnWidth(8,10);
		writer.setColumnWidth(9,10);
         response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("慢病人员药品使用统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    
    //药物使用情况统计表
    @RequestMapping("/ywsyqktjb") 
    public Object ywsyqktjb(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String hosnum = request.getParameter("hosnum");
		String year = request.getParameter("searchYear");
		return reportCardService.ywsyqktjb(hosnum, year);
    }
    
    
    //导出药物使用情况统计表
    @RequestMapping("/exportYwsyqktjbStatistics")
    public void exportYwsyqktjbStatistics(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String hosnum = request.getParameter("hosnum");
		String year = request.getParameter("searchYear");
		List<Map<String, Object>> ywsyqktjb = reportCardService.ywsyqktjb(hosnum, year);
		ExcelWriter writer = ExcelUtil.getWriter();
		List<String> header1 = new LinkedList<>();
		header1.add("序号");
		header1.add("药品名称");
		header1.add("人数");
		writer.writeHeadRow(header1);
		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<ywsyqktjb.size();i++){
			Map<String, Object> map = ywsyqktjb.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(""+(i+1),map.get("medName").toString(),map.get("count").toString());
			rows.add(row);
		}
		writer.write(rows,true);
		//调整列宽度
		writer.setColumnWidth(0, 10);
		writer.setColumnWidth(1, 20);
		writer.setColumnWidth(2, 10);
         response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("药物使用情况统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    
    //导出慢病患者健康档案查询表
    @RequestMapping("/exportMbhealthFilesStatistics")
    public void exportMbhealthFilesStatistics(HttpServletRequest request, HttpServletResponse response,MbReportCard mbReportCard) throws Exception{
		List<Map<String, Object>> mbhealthFilesList = reportCardService.getMbhealthFilesList(mbReportCard);
		ExcelWriter writer = ExcelUtil.getWriter();
		List<String> header1 = new LinkedList<>();
		header1.add("患者姓名");
		header1.add("慢病类型");
		header1.add("身份证号");
		header1.add("联系电话");
		header1.add("首次诊断日期");
		header1.add("诊断单位");
		header1.add("报卡日期");
		header1.add("上报日期");
		writer.writeHeadRow(header1);
		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<mbhealthFilesList.size();i++){
			Map<String, Object> map = mbhealthFilesList.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(map.get("patientName").toString()
					,map.get("mbType").toString(),map.get("idCardNo").toString(),map.get("lxdh").toString()
					,map.get("sczdrq").toString(),map.get("zgzddw").toString(),map.get("bkrq").toString()
					,map.get("sbTime")==null?"":map.get("sbTime").toString());
			rows.add(row);
		}
		writer.write(rows,true);
		//调整列宽度
		writer.setColumnWidth(0, 10);
		writer.setColumnWidth(1, 20);
		writer.setColumnWidth(2, 20);
		writer.setColumnWidth(3, 15);
		writer.setColumnWidth(4, 15);
		writer.setColumnWidth(5, 15);
		writer.setColumnWidth(6, 15);
		writer.setColumnWidth(7, 15);
		response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("慢病患者健康档案查询表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    
    /**
     * 体检人群统计表
     * @param request
     * @param rgesponse
     * @return
     */
    @RequestMapping("/pexamPopulation")
    public Object pexamPopulation(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		List<Map<String, Object>> pexamPopulation = reportCardService.pexamPopulation(hosnum,startDate,endDate);
		return pexamPopulation;
    }

	/**
	 * 体检人群统计表（新）、体检人群分析表
	 * @param request
	 * @param rgesponse
	 * @return
	 */
	@RequestMapping("/pexamPopulation2")
	public Object pexamPopulation2(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
//		String startDate = request.getParameter("startDate");
//		String endDate = request.getParameter("endDate");
		String queryDay=request.getParameter("queryDay");
		List<Map<String, Object>> pexamPopulation = reportCardService.pexamPopulation2(hosnum,queryDay);
		System.out.println("==体检人群统计表=="+pexamPopulation.get(0));
		return pexamPopulation;
	}
    
    
    //导出体检人群统计表
    @RequestMapping("/exportPexamPopulationStatistics")
    public void exportPexamPopulationStatistics(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate").equals("null")?"":request.getParameter("startDate");
		String endDate = request.getParameter("endDate").equals("null")?"":request.getParameter("endDate");
		List<Map<String, Object>> pexamPopulation = reportCardService.pexamPopulation(hosnum,startDate,endDate);
		ExcelWriter writer = ExcelUtil.getWriter();
		List<String> header = new LinkedList<>();
		header.add("体检人群统计表");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		writer.writeHeadRow(header);
		writer.merge(0,0,0,7,null,false);
		List<String> header1 = new LinkedList<>();
		header1.add("所属区域");
		header1.add("0-6岁");
		header1.add("7-14岁");
		header1.add("15-25岁");
		header1.add("26-35岁");
		header1.add("36-45岁");
		header1.add("46-55岁");
		header1.add("55岁以上");
		writer.writeHeadRow(header1);
		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<pexamPopulation.size();i++){
			Map<String, Object> map = pexamPopulation.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(map.get("cunName").toString()
					,map.get("a").toString(),map.get("b").toString(),map.get("c").toString()
					,map.get("d").toString(),map.get("e").toString(),map.get("f").toString()
					,map.get("g").toString());
			rows.add(row);
		}
		writer.write(rows,true);
		//调整列宽度
		writer.setColumnWidth(0, 50);
		writer.setColumnWidth(1, 10);
		writer.setColumnWidth(2, 10);
		writer.setColumnWidth(3, 10);
		writer.setColumnWidth(4, 10);
		writer.setColumnWidth(5, 10);
		writer.setColumnWidth(6, 10);
		writer.setColumnWidth(7, 10);
		response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("体检人群统计表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }


	/**
     * 获取个人体检频次表人员
     * @param request
     * @param rgesponse
     * @return
     */
    @RequestMapping("/getTjpcName")
    public Object getTjpcName(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
		String populationName = request.getParameter("populationName");
		List<Map<String, Object>> pexamPopulation = reportCardService.getTjpcName(hosnum,populationName);
		return pexamPopulation;
    }
    
    /**
     * 个人体检频次表
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/getTjpcfo")
    public Object getTjpcfo(HttpServletRequest request,HttpServletResponse response){
		String populationId = request.getParameter("populationId");
		Map<String, Object> tjpcfo = reportCardService.getTjpcfo(populationId);
		return tjpcfo;
    }
    
    
    //导出个人体检频次表
    @SuppressWarnings("unchecked")
    @RequestMapping("/exportTjpcStatistics")
    public void exportTjpcStatistics(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String populationId = request.getParameter("populationId");
		Map<String, Object> tjpcfo = reportCardService.getTjpcfo(populationId);
		//人员基本信息
		Map<String,Object> populationInfoMap = (Map<String,Object>)tjpcfo.get("populationInfo");
		//体检基本信息
		List<Map<String,Object>> pexamInfo = (List<Map<String,Object>>)tjpcfo.get("pexamInfo");
		ExcelWriter writer = ExcelUtil.getWriter();
		//去掉头部背景颜色
		StyleSet styleSet = writer.getStyleSet();
		styleSet.setBackgroundColor(IndexedColors.WHITE, true);
		List<String> header1 = new LinkedList<>();
		header1.add("姓名");
		header1.add(populationInfoMap.get("name").toString());
		header1.add("性别");
		header1.add(populationInfoMap.get("sex").toString());
		header1.add("出生日期");
		header1.add(populationInfoMap.get("birthday").toString());
		writer.writeHeadRow(header1);
		List<String> header2 = new LinkedList<>();
		header2.add("身份证号");
		header2.add(populationInfoMap.get("idnumber").toString());
		header2.add("手机号");
		header2.add(populationInfoMap.get("telephony").toString());
		header2.add("婚姻状况");
		header2.add(populationInfoMap.get("marriage").toString());
		writer.writeHeadRow(header2);
		List<String> header3 = new LinkedList<>();
		header3.add("体检时间");
		header3.add("");
		header3.add("体检单位");
		header3.add("");
		header3.add("体检单号");
		header3.add("");
		writer.writeHeadRow(header3);
		writer.merge(2,2,0,1,null,false);
		writer.merge(2,2,2,3,null,false);
		writer.merge(2,2,4,5,null,false);

		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<pexamInfo.size();i++){
			Map<String,Object> map=pexamInfo.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(
					map.get("inspectTime").toString(),"",
					map.get("codeName").toString(),"",
					"","");
			rows.add(row);
		}
		writer.write(rows,true);
		for(int i=3;i<3+(pexamInfo.size());i++){
			writer.merge(i,i,0,1,null,false);
			writer.merge(i,i,2,3,null,false);
			writer.merge(i,i,4,5,null,false);
		}
		//调整列宽度
		writer.setColumnWidth(0,15);
		writer.setColumnWidth(1,20);
		writer.setColumnWidth(2,15);
		writer.setColumnWidth(3,15);
		writer.setColumnWidth(4, 15);
		writer.setColumnWidth(5, 15);

         response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("个人体检频次表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    //风险指数统计
    @RequestMapping("/fxzs")
    public Object fxzs(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		Map<String,Object> fxzs = reportCardService.getFxzsList(hosnum,startDate,endDate);
		return fxzs;
    }
    
    
    //风险指数统计
    @RequestMapping("/exportFxzsStatistics")
    public void exportFxzsStatistics(HttpServletRequest request,HttpServletResponse response){
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		Map<String,Object> fxzs = reportCardService.getFxzsList(hosnum,startDate,endDate);
		ExcelWriter writer = ExcelUtil.getWriter();
		List<String> header = new LinkedList<>();
		header.add("风险指数统计");  //0
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		header.add("");
		writer.writeHeadRow(header);
		writer.merge(0,0,0,16,null,false);
		List<String> header1 = new LinkedList<>();
		header1.add("所属区域");  //0
		header1.add("心梗");
		header1.add("血糖");
		header1.add("疲劳");
		header1.add("抑郁");  //5
		header1.add("咽炎");
		header1.add("胃炎");
		header1.add("颈椎病"); //7
		header1.add("脊柱不正");
		header1.add("血压"); //9
		header1.add("血脂");
		header1.add("焦虑"); //11
		header1.add("睡眠");
		header1.add("免疫力");
		header1.add("胃动力不足");
		header1.add("脑供血不足"); //15
		header1.add("肾功能减退");
		writer.writeHeadRow(header1);

		List<List<String>> rows = new LinkedList<>();
		List<Map<String,Object>> fxzsList = (List<Map<String,Object>>)fxzs.get("fxzs");
		for(int i=0;i<fxzsList.size();i++){
			Map<String,Object> item = fxzsList.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(item.get("codeName").toString(),
					item.get("xg").toString(),
					item.get("xt").toString(),
					item.get("pl").toString(),
					item.get("yiyu").toString(),
					item.get("yany").toString(),
					item.get("wy").toString(),
					item.get("jzb").toString(),
					item.get("jzbz").toString(),
					item.get("xy").toString(),
					item.get("xz").toString(),
					item.get("jl").toString(),
					item.get("sm").toString(),
					item.get("myl").toString(),
					item.get("wdlbz").toString(),
					item.get("ngxbz").toString(),
					item.get("sgnjt").toString()
			);
			rows.add(row);
		}
		writer.write(rows,true);
		//合计
		List<List<String>> total = new LinkedList<>();
		List<String> array = CollUtil.newLinkedList("合计",
				fxzs.get("xgTotal").toString(),
				fxzs.get("xtTotal").toString(),
				fxzs.get("plTotal").toString(),
				fxzs.get("yiyuTotal").toString(),
				fxzs.get("yanyTotal").toString(),
				fxzs.get("wyTotal").toString(),
				fxzs.get("jzbTotal").toString(),
				fxzs.get("jzbzTotal").toString(),
				fxzs.get("xyTotal").toString(),
				fxzs.get("xzTotal").toString(),
				fxzs.get("jlTotal").toString(),
				fxzs.get("smTotal").toString(),
				fxzs.get("mylTotal").toString(),
				fxzs.get("wdlbzTotal").toString(),
				fxzs.get("ngxbzTotal").toString(),
				fxzs.get("sgnjtTotal").toString()
		);
		total.add(array);
		writer.write(total,true);
		//调整列宽度
		writer.setColumnWidth(0, 50);
		writer.setColumnWidth(1, 8);
		writer.setColumnWidth(2, 8);
		writer.setColumnWidth(3,8);
		writer.setColumnWidth(4, 15);
		writer.setColumnWidth(5, 10);
		writer.setColumnWidth(6,10);
		writer.setColumnWidth(7,15);
		writer.setColumnWidth(8,10);
		writer.setColumnWidth(9,15);
		writer.setColumnWidth(10, 10);
		writer.setColumnWidth(11, 15);
		writer.setColumnWidth(12, 10);
		writer.setColumnWidth(13,10);
		writer.setColumnWidth(14, 15);
		writer.setColumnWidth(15, 10);
		writer.setColumnWidth(16,10);
		response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("风险指数统计".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    /**
     * 症状指标查询
     * @param request
     * @param response
     * @param mbreportCard
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getZzzb", method = RequestMethod.POST)
	public Object getZzzb(HttpServletRequest request, HttpServletResponse response,MbReportCard mbreportCard) throws Exception {
		IPage<MbReportCard> list = reportCardService.getZzzb(mbreportCard);
		return list;
	}
    
    
    //导出症状指标查询表
    @RequestMapping("/exportZzzbStatistics")
    public void exportZzzbStatistics(HttpServletRequest request, HttpServletResponse response,MbReportCard mbReportCard) throws Exception{
		List<MbReportCard> mbhealthFilesList = reportCardService.getZzzbExport(mbReportCard);
		ExcelWriter writer = ExcelUtil.getWriter();
		List<String> header1 = new LinkedList<>();
		header1.add("序号");
		header1.add("姓名");
		header1.add("性别");
		header1.add("年龄");
		header1.add("身份证号");
		header1.add("电话");
		header1.add("慢病类型");
		header1.add("症状");
		writer.writeHeadRow(header1);
		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<mbhealthFilesList.size();i++){
			MbReportCard map = mbhealthFilesList.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(""+(i+1),map.getPatientName(),map.getPatientSex(),
					map.getAge(),map.getIdCardNo(),map.getLxdh(),map.getMbType(),map.getZs());
			rows.add(row);
		}
		writer.write(rows,true);
		//调整列宽度
		writer.setColumnWidth(0, 10);
		writer.setColumnWidth(1, 20);
		writer.setColumnWidth(2, 20);
		writer.setColumnWidth(3, 15);
		writer.setColumnWidth(4, 20);
		writer.setColumnWidth(5, 15);
		writer.setColumnWidth(6, 15);
		writer.setColumnWidth(7, 30);
		response.setContentType("application/vnd.ms-excel;charset=utf-8");
         String fileName = new String("症状指标查询表".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
         response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         ServletOutputStream out = null;
         try {
              out = response.getOutputStream();
              writer.flush(out, true);
         } catch (IOException e) {
              e.printStackTrace();
         } finally {
              // 关闭writer，释放内存
              writer.close();
         }
         //此处记得关闭输出Servlet流
         IoUtil.close(out);
    }
    
    
    /**
     * 获取文化程度
     * @param request
     * @param rgesponse
     * @return
     */
    @RequestMapping("/getStudyheight")
    public Object getSTUDYHEIGHT(HttpServletRequest request,HttpServletResponse rgesponse){
		List<Codelist> fxzs = iCodelistService.getSTUDYHEIGHT();
		return fxzs;
    }
    
    /**
     * 患者健康档案查询
     * @param request
     * @param response
     * @param mbreportCard
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMbHealthFile", method = RequestMethod.POST)
	public Object getMbHealthFile(HttpServletRequest request, HttpServletResponse response,MbReportCard mbreportCard) throws Exception {
		IPage<Map<String,Object>> list = reportCardService.getMbHealthFile(mbreportCard);
		return list;
	}


	@GetMapping("/gecunrenshu")
	public List gecunrenshu(@Param("mbType") String mbType){
		return reportCardService.gecunrenshu(mbType);
	}

	@GetMapping("/gecunrenshush")
	public List gecunrenshush(@Param("mbType") String mbType){
		return reportCardService.gecunrenshush(mbType);
	}


	@RequestMapping("/getJbfxList")
	public IPage<Map<String,Object>> getJbfxList(JbfxReport jbfxReport){
		return reportCardService.getJbfxList(jbfxReport);
	}


	//疾病风险查询
	@RequestMapping("/exportJbfx")
	public void exportJbfx(JbfxReport jbfxReport,HttpServletRequest request, HttpServletResponse response){
		List<Map<String,Object>> jbfx = reportCardService.exportJbfxList(jbfxReport);
		ExcelWriter writer = ExcelUtil.getWriter();
		List<String> header1 = new LinkedList<>();
		header1.add("姓名");  //0
		header1.add("年龄");
		header1.add("性别");
		header1.add("身份证号");
		header1.add("慢病信息");  //5
		header1.add("体检时间");
		header1.add("疾病风险");
		writer.writeHeadRow(header1);

		List<List<String>> rows = new LinkedList<>();
		for(int i=0;i<jbfx.size();i++){
			Map<String,Object> item = jbfx.get(i);
			LinkedList<String> row = CollUtil.newLinkedList(
					item.get("name").toString(),
					item.get("age").toString(),
					item.get("sex").toString(),
					item.get("idnumber").toString(),
					item.get("chronic").toString(),
					item.get("exaimTime").toString(),
					item.get("text").toString()
			);
			rows.add(row);
		}
		writer.write(rows,true);
		//调整列宽度
		writer.setColumnWidth(0, 15);
		writer.setColumnWidth(1, 8);
		writer.setColumnWidth(2, 8);
		writer.setColumnWidth(3,30);
		writer.setColumnWidth(4, 15);
		writer.setColumnWidth(5, 15);
		writer.setColumnWidth(6,50);
		response.setContentType("application/vnd.ms-excel;charset=utf-8");
		String fileName = new String("疾病风险查询".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
		response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			writer.flush(out, true);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭writer，释放内存
			writer.close();
		}
		//此处记得关闭输出Servlet流
		IoUtil.close(out);
	}

	//脏腑辩证统计
	@RequestMapping("/zfbz")
	public Object zfbz(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		List<Map<String,Object>> fxzs = reportCardService.zfbzList(hosnum,startDate,endDate);
		return fxzs;
	}


	@RequestMapping("/exportTjzfbztj")
	public void exportTjzfbztj(HttpServletRequest request, HttpServletResponse response){
		try {
			String startDate=request.getParameter("startDate");
			String endDate=request.getParameter("endDate");
			String hosnum=request.getParameter("hosnum");
			List<Map<String,Object>> list = reportCardService.zfbzList(hosnum,startDate,endDate);

			ExcelWriter writer = ExcelUtil.getWriter();
			List<String> header0 = new LinkedList<>();
			header0.add(startDate+"~"+endDate+"脏腑辨证统计");
			writer.writeHeadRow(header0);
			writer.merge(0,0,0,22,null,false);
			List<String> header1 = new LinkedList<>();
			header1.add("所属区域");
			header1.add("心肾不交");
			header1.add("肾阳虚");
			header1.add("肾阴虚");
			header1.add("脾胃不调，胃火偏旺");
			header1.add("湿热困脾");
			header1.add("寒湿困脾");
			header1.add("心血瘀阻");
			header1.add("肺失宣泄，肺气不足");
			header1.add("心气不足");
			header1.add("心火上炎");
			header1.add("肝气郁结，肝血亏虚");
			header1.add("气血双虚");
			header1.add("心血亏虚");
			header1.add("肝火上炎");
			header1.add("肝血亏虚");
			header1.add("肝气郁结");
			header1.add("胃阴虚");
			header1.add("胃气不足");
			header1.add("胆火旺");
			header1.add("胆气虚");
			header1.add("脾气虚");
			header1.add("脏腑功能良好");
			writer.writeHeadRow(header1);
			List<List<String>> rows = new LinkedList<>();
			list.forEach(val -> {
				Map<String,Object> map = val;
				LinkedList<String> row = CollUtil.newLinkedList(
						map.get("codeName").toString(),
						map.get("xsbj").toString(),
						map.get("syinx").toString(),
						map.get("syangx").toString(),
						map.get("pw").toString(),
						map.get("srkp").toString(),
						map.get("shkp").toString(),
						map.get("xxyz").toString(),
						map.get("ff").toString(),
						map.get("xqbz").toString(),
						map.get("xhsy").toString(),
						map.get("gg").toString(),
						map.get("qxsk").toString(),
						map.get("xxkx").toString(),
						map.get("ghsy").toString(),
						map.get("gxkx").toString(),
						map.get("gqyj").toString(),
						map.get("wyx").toString(),
						map.get("wqbz").toString(),
						map.get("dhw").toString(),
						map.get("dqx").toString(),
						map.get("pqx").toString(),
						map.get("lh").toString()
				);
				rows.add(row);
			});
			writer.write(rows,true);

			writer.setColumnWidth(0,50);
			writer.setColumnWidth(1,15);
			writer.setColumnWidth(2,15);
			writer.setColumnWidth(3,15);
			writer.setColumnWidth(4,20);
			writer.setColumnWidth(5,15);
			writer.setColumnWidth(6,15);
			writer.setColumnWidth(7,15);
			writer.setColumnWidth(8,20);
			writer.setColumnWidth(9,15);
			writer.setColumnWidth(10,15);
			writer.setColumnWidth(11,20);
			writer.setColumnWidth(12,15);
			writer.setColumnWidth(13,15);
			writer.setColumnWidth(14,15);
			writer.setColumnWidth(15,15);
			writer.setColumnWidth(16,15);
			writer.setColumnWidth(17,15);
			writer.setColumnWidth(18,15);
			writer.setColumnWidth(19,15);
			writer.setColumnWidth(20,15);
			writer.setColumnWidth(21,15);
			writer.setColumnWidth(22,15);


			response.setContentType("application/vnd.ms-excel;charset=utf-8");
			String fileName = new String("脏腑辨证统计".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
			response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
			ServletOutputStream out = null;
			try {
				out = response.getOutputStream();
				writer.flush(out, true);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				// 关闭writer，释放内存
				writer.close();
			}
			//此处记得关闭输出Servlet流
			IoUtil.close(out);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	//脏腑辩证统计
	@RequestMapping("/getTzbzList")
	public Object getTzbzList(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		List<Map<String,Object>> fxzs = reportCardService.getTzbzList(hosnum,startDate,endDate);
		System.out.println("==辩证统计=="+fxzs.get(0));
		return fxzs;
	}

	//脏腑辩证统计(新)
	@RequestMapping("/getTzbzList2")
	public Object getTzbzList2(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
//		String startDate = request.getParameter("startDate");
//		String endDate = request.getParameter("endDate");
		String queryDay=request.getParameter("queryDay");
		List<Map<String,Object>> fxzs = reportCardService.getTzbzList2(hosnum,queryDay);
		System.out.println("==辩证统计(新)=="+fxzs.get(0));
		return fxzs;
	}


	@RequestMapping("/exportTzbz")
	public void exportTzbz(HttpServletRequest request, HttpServletResponse response){
		try {
			String hosnum=request.getParameter("hosnum");
			String startDate = request.getParameter("startDate");
			String endDate = request.getParameter("endDate");
			List<Map<String,Object>> list = reportCardService.getTzbzList(hosnum,startDate,endDate);

			ExcelWriter writer = ExcelUtil.getWriter();
			List<String> header0 = new LinkedList<>();
			header0.add("体质辨证统计");
			writer.writeHeadRow(header0);
			writer.merge(0,0,0,20,null,false);
			List<String> header1 = new LinkedList<>();
			header1.add("所属区域");
			header1.add("阳虚质");
			header1.add("阴虚质");
			header1.add("气虚质");
			header1.add("气郁质");
			//header1.add("倾向气郁质（脉弦）");
			//header1.add("倾向阴虚质（脉细数）");
			header1.add("平和倾向阳虚质");
			header1.add("接近平和质");
			header1.add("倾向气虚质");
			//header1.add("接近平和质（脉平稍数）");
			//header1.add("接近平和质（脉平稍细）");
			header1.add("平和质");
			header1.add("痰湿质兼血瘀质");
			header1.add("痰湿质");
			header1.add("湿热质");
			header1.add("血瘀质");
			header1.add("倾向气郁质");
			header1.add("倾向阴虚质");
			header1.add("倾向阳虚质");
			header1.add("平和质倾向阴虚质");
			header1.add("阴虚质兼血瘀质");
			header1.add("阴虚质兼痰湿质");
			header1.add("阴虚质兼湿热质");
			header1.add("阴虚质兼气郁质");
			//header1.add("阳虚质兼气郁质（脉沉涩）");
			writer.writeHeadRow(header1);
			List<List<String>> rows = new LinkedList<>();
			list.forEach(val -> {
				Map<String,Object> map = val;
				LinkedList<String> row = CollUtil.newLinkedList(
						map.get("codeName").toString(),
						map.get("yangxz").toString(),
						map.get("yinxz").toString(),
						map.get("qxz").toString(),
						map.get("qyz").toString(),
						//map.get("qyz1").toString(),
						//map.get("qyz2").toString(),
						map.get("phzqxyanxz").toString(),
						map.get("jjphz").toString(),
						map.get("qxqxz").toString(),
						//map.get("phz1").toString(),
						//map.get("phz2").toString(),
						map.get("phz").toString(),
						map.get("tszjxyz").toString(),
						map.get("tsz").toString(),
						map.get("srz").toString(),
						map.get("xyz").toString(),
						map.get("qxqyz").toString(),
						map.get("qxyinxz").toString(),
						map.get("qxyanxz").toString(),
						map.get("phzqxyinxz").toString(),
						map.get("yxzjxyz").toString(),
						map.get("yxzjtsz").toString(),
						map.get("yxzjsrz").toString(),
						map.get("yxzjqyz").toString()
						//map.get("yangxzjqyz").toString()
				);
				rows.add(row);
			});
			writer.write(rows,true);
			writer.setColumnWidth(0,50);
			//writer.setColumnWidth(1,20);
			//writer.setColumnWidth(2,20);
			//writer.setColumnWidth(3,20);
			//writer.setColumnWidth(4,20);
			writer.setColumnWidth(5,20);
			writer.setColumnWidth(6,15);
			writer.setColumnWidth(7,15);
			//writer.setColumnWidth(8,20);
			writer.setColumnWidth(9,20);
			//writer.setColumnWidth(10,20);
			//writer.setColumnWidth(11,20);
			//writer.setColumnWidth(12,20);
			writer.setColumnWidth(13,15);
			writer.setColumnWidth(14,15);
			writer.setColumnWidth(15,15);
			writer.setColumnWidth(16,20);
			writer.setColumnWidth(17,20);
			writer.setColumnWidth(18,20);
			writer.setColumnWidth(19,20);
			writer.setColumnWidth(20,20);

			response.setContentType("application/vnd.ms-excel;charset=utf-8");
			String fileName = new String("体质辨证统计".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
			response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
			ServletOutputStream out = null;
			try {
				out = response.getOutputStream();
				writer.flush(out, true);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				// 关闭writer，释放内存
				writer.close();
			}
			//此处记得关闭输出Servlet流
			IoUtil.close(out);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	//脏腑辩证统计
	@RequestMapping("/getTzList")
	public IPage<Map<String,Object>> getTzList(HttpServletRequest request,HttpServletResponse rgesponse){
		String hosnum = request.getParameter("hosnum");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		String pname = request.getParameter("pname");
		String pageIndex = request.getParameter("pageIndex");
		String pageSize = request.getParameter("pageSize");
		IPage<Map<String,Object>> tx = reportCardService.getTzList(hosnum,startDate,endDate,pname,Integer.parseInt(pageIndex),Integer.parseInt(pageSize));
		return tx;
	}


	@RequestMapping("/exportTz")
	public void exportTz(HttpServletRequest request, HttpServletResponse response){
		try {
			String hosnum = request.getParameter("hosnum");
			String startDate = request.getParameter("startDate");
			String endDate = request.getParameter("endDate");
			String pname = request.getParameter("pname");
			String pageIndex = request.getParameter("pageIndex");
			String pageSize = request.getParameter("pageSize");
			IPage<Map<String,Object>> ipage = reportCardService.getTzList(hosnum,startDate,endDate,pname,Integer.parseInt(pageIndex),Integer.parseInt(pageSize));
			List<Map<String,Object>> tz = ipage.getRecords();
			ExcelWriter writer = ExcelUtil.getWriter();
			List<String> header1 = new LinkedList<>();
			header1.add("所属区域");
			header1.add("姓名");
			header1.add("体检时间");
			header1.add("阴指数");
			header1.add("阳指数");
			header1.add("血瘀指数");
			header1.add("湿气指数");
			writer.writeHeadRow(header1);
			List<List<String>> rows = new LinkedList<>();
			tz.forEach(val -> {
				Map<String,Object> map = val;
				LinkedList<String> row = CollUtil.newLinkedList(
						map.get("codeName").toString(),
						map.get("name").toString(),
						map.get("examTime").toString(),
						map.get("yin").toString(),
						map.get("yang").toString(),
						map.get("xueyu").toString(),
						map.get("shiqi").toString()
				);
				rows.add(row);
			});
			writer.write(rows,true);
			response.setContentType("application/vnd.ms-excel;charset=utf-8");
			String fileName = new String("体征查询".getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1);
			response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
			ServletOutputStream out = null;
			try {
				out = response.getOutputStream();
				writer.flush(out, true);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				// 关闭writer，释放内存
				writer.close();
			}
			//此处记得关闭输出Servlet流
			IoUtil.close(out);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
